<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        //表单对象
        let form;
        function load() {
           form=document.forms['frm'];
           form.btnNumber.addEventListener('click',numberCheck);
           form.btnEnglish.addEventListener('click',englishCheck);
           form.btnWord.addEventListener('click',wordCheck);
           form.btnIP.addEventListener('click',ipChenk);
        }
        function numberCheck() {
            //只能写数字
            // let reg = /^[0-9]$;   //一个数字
            //let reg = /^[0-9]{1,3}$/;  //至少一个数字，最多3个数字
            let reg = /^\d+$/;
            let value = document.forms['frm'].info.value;
            form.info.nextElementSibling.innerText=reg.test(value) ? "通过" : "不通过";
        }
        function englishCheck() {
            //英文字母校验
            let reg= /^[a-zA-Z]+$/
            let value=form.info.value;
            form.info.nextElementSibling.innerText=reg.test(value) ? "通过" : "不通过";
        }
        function wordCheck() {
            let reg = /^\w+$/;
            let value =form.info.value;
            form.info.nextElementSibling.innerHTML=
                reg.test(value)?'pass':'fail';
        }
        function ipChenk() {
            let rag =/^(\d|[1-9\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9\d])\.(\d|[1-9\d])$/
            let value=form.info.value;
            form.info.nextElementSibling.innerHTML=
                rag.test(value)?'pass':'fail';
        }
    </script>
</head>
<body onload="load()">
<form name="frm">
    字符串<input name="info"><span></span><br/>
    <button name="btnNumber" type="button">数字</button>
    <button name="btnEnglish" type="button">英文</button>
    <button name="btnWord" type="button">单词</button>
    <button name="btnIP" type="button">IP</button>
</form>
</body>
</html>